package com.jiangyg.mall.order.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.order.dto.OrderSettingDTO;
import com.jiangyg.mall.order.service.OrderSettingService;
import com.jiangyg.mall.order.vo.OrderSettingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：订单配置信息控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:36:28
 */
@RestController
@RequestMapping("/order/orderSetting")
public class OrderSettingController {

    /**
     * 订单配置信息接口
     */
    private final OrderSettingService orderSettingService;

    @Autowired
    public OrderSettingController(OrderSettingService orderSettingService) {
        this.orderSettingService = orderSettingService;
    }

    /**
     * 功能描述：订单配置信息分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页订单配置信息
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<OrderSettingVO>> select(HttpServletRequest request, @RequestBody Pagination<OrderSettingVO> pagination) throws Exception {
        return Result.ok(orderSettingService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改订单配置信息
     *
     * @param request 请求
     * @param dto     订单配置信息
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated OrderSettingDTO dto) throws Exception {
        return Result.saveOrUpdate(orderSettingService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取订单配置信息
     *
     * @param request 请求
     * @param orderSettingId  订单配置信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<OrderSettingVO> info(HttpServletRequest request, @RequestParam(name = "orderSettingId") Long orderSettingId) throws Exception {
        return Result.ok(orderSettingService.selectById(orderSettingId));
    }

    /**
     * 功能描述：删除订单配置信息
     *
     * @param request 请求
     * @param orderSettingIds 批量删除的订单配置信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "orderSettingIds") List<Long> orderSettingIds) {
        return Result.delete(orderSettingService.delete(orderSettingIds));
    }

}
